#!/usr/bin/env python3
"""
进程池实现示例
"""

from multiprocessing import Pool
import time

def worker_task(n):
    """模拟耗时任务"""
    print(f"处理任务 {n}...")
    time.sleep(1)
    return n * n

def main():
    # 创建进程池（4个worker进程）
    with Pool(processes=4) as pool:
        # 提交10个任务
        tasks = range(10)
        results = pool.map(worker_task, tasks)
        
        print(f"所有任务完成！结果: {results}")

if __name__ == '__main__':
    main()

